<?php

class CommonsUpdateController extends CommonsController
{

    public $layout='/layouts/column2';
    public function actionDestinationUpdate(){
        Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
        $token = CHtml::encode(Yii::app()->request->getParam('token'));
        $info = Article::model()->find('token=:token',array(':token'=>$token));
        if(Yii::app()->request->isPostRequest){
            if(!$_POST['thumb']){
                $data['status'] = 0;
                $data['message'] = '请上传缩略图';
                echo json_encode($data);
                Yii::app()->end();
            }else{
                $_POST['Article']['thumb'] = $_POST['thumb'];
            }
            $_POST['Article']['people'] = implode(",",$_POST['people']);
            $_POST['Article']['theme'] = implode(",",$_POST['theme']);
            if($info){
                $info->setAttributes($_POST['Article']);
                if($info->update()){
                    $id = $info->id;
                    $data_model = ArticleData::model()->find('article_id=:article_id',array(':article_id'=>$id));
                    //写入附表Data
                    $data_model->content = CHtml::encode($_POST['content']);
                    $data_model->setAttributes($_POST['ArticleData']);
                    if($data_model->update()){
                        //图片  设为删除   is_delete = 0
                        ArticleImages::model()->deleteAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'public',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                        //添加新图片地址
                        if($_POST['image_path']){
                            $image_arr = $_POST['image_path'];
                            foreach($image_arr as $k=>$v){
                                Xtutuquan::createArticleImage($id,'public',$v);
                            }
                        }
                        //修改  周边表status = 0;
                        ArticleAmbitus::model()->deleteAll('source_id=:source_id and status=:status',array(':source_id'=>$info->id,':status'=>1));
                        //新增周边
                        if($_POST['relation']){
                            $relation_arr = $_POST['relation'];
                            foreach($relation_arr as $k=>$v){
                                Xtutuquan::createArticleAmbitus($id,$v);
                            }
                        }
                        //写入周边
                        $data['status'] = 1;
                        $data['message'] = '景点修改成功';
                    }else{
                        $data['status'] = 0;
                        $data['message'] = $this->showError($data_model->getErrors());
                    }
                }else{
                    $data['status'] = 0;
                    $data['message'] = $this->showError($info->getErrors());
                }
            }else{
                $data['status'] = 0;
                $data['message'] = '你无权作此操作';
            }
            echo json_encode($data);
            Yii::app()->end();
        }
        if(!$info){
            $message = '不存在此数据';
            $this->renderPartial('404',array('message'=>$message));
            Yii::app()->end();
        }
        if($info->is_link==0){
            $message = '修改链接已关闭';
            $this->renderPartial('404',array('message'=>$message));
            Yii::app()->end();
        }

        $city_array = CityArea::model()->findAll('city_id=:city_id and status=:status',array(':city_id'=>$info->city_id,':status'=>1));

        if($city_array){
            $level	= Xtutuquan::jibieArr();
            $people = Xtutuquan::renqunArr();
            $theme = Xtutuquan::zhutiArr();
            $city_info  = CreateCity::model()->findByPk($info->city_id);
            $this->layout = '/layouts/dialog';
            if($info){
                //获取附表
                $info_data = ArticleData::model()->find('article_id=:article_id',array(':article_id'=>$info->id));
                //获取图集
                $image_info = ArticleImages::model()->findAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'public',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                //获取周边
                $ambitus_info = ArticleAmbitus::model()->with('au')->findAll('source_id=:source_id and status=:status',array(':source_id'=>$info->id,':status'=>1));

                $this->render('destinationUpdate',array('ambitus_info'=>$ambitus_info,'image_info'=>$image_info,'info_data'=>$info_data,'info'=>$info,'city'=>$city_array,'level'=>$level,'people'=>$people,'theme'=>$theme,'city_info'=>$city_info));
            }else{
                exit('你无此权限');
            }
        }else{
            exit('总后台添加区域数据');
        }
    }


    public function actionHotelUpdate(){
        Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
        $token = CHtml::encode(Yii::app()->request->getParam('token'));
        $info = Article::model()->find('token=:token',array(':token'=>$token));
        if(Yii::app()->request->isPostRequest){
            if(!$_POST['thumb']){
                $data['status'] = 0;
                $data['message'] = '请上传缩略图';
                echo json_encode($data);
                Yii::app()->end();
            }else{
                $_POST['Article']['thumb'] = $_POST['thumb'];
            }
            $_POST['Article']['people'] = implode(",",$_POST['people']);
            $_POST['Article']['theme'] = implode(",",$_POST['theme']);
            if($info){
                $info->setAttributes($_POST['Article']);
                if($info->update()){
                    $id = $info->id;
                    $data_model = ArticleData::model()->find('article_id=:article_id',array(':article_id'=>$id));
                    //写入附表Data
                    $data_model->content = CHtml::encode($_POST['content']);
                    $data_model->setAttributes($_POST['ArticleData']);
                    if($data_model->update()){
                        //图片  设为删除   is_delete = 0
                        ArticleImages::model()->deleteAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'public',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                        //添加新图片地址
                        if($_POST['image_path']){
                            $image_arr = $_POST['image_path'];
                            foreach($image_arr as $k=>$v){
                                Xtutuquan::createArticleImage($id,'public',$v);
                            }
                        }
                        //图片 住宿 设为删除
                        ArticleImages::model()->deleteAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'zhusu',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                        //添加新图片地址
                        if($_POST['image_zhusu_path']){
                            $image_arr = $_POST['image_zhusu_path'];
                            foreach($image_arr as $k=>$v){
                                Xtutuquan::createArticleImage($id,'zhusu',$v);
                            }
                        }
                        //图片 美食 设为删除
                        ArticleImages::model()->deleteAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'food',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                        //添加新图片地址
                        if($_POST['image_food_path']){
                            $image_arr = $_POST['image_food_path'];
                            foreach($image_arr as $k=>$v){
                                Xtutuquan::createArticleImage($id,'food',$v);
                            }
                        }
                        //图片 好玩的 设为删除
                        ArticleImages::model()->deleteAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'happy',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                        //添加新图片地址
                        if($_POST['image_happy_path']){
                            $image_arr = $_POST['image_happy_path'];
                            foreach($image_arr as $k=>$v){
                                Xtutuquan::createArticleImage($id,'happy',$v);
                            }
                        }
                        //修改  周边表status = 0;
                        ArticleAmbitus::model()->deleteAll('source_id=:source_id and status=:status',array(':source_id'=>$info->id,':status'=>1));
                        //新增周边
                        if($_POST['relation']){
                            $relation_arr = $_POST['relation'];
                            foreach($relation_arr as $k=>$v){
                                Xtutuquan::createArticleAmbitus($id,$v);
                            }
                        }
                        //写入周边
                        $data['status'] = 1;
                        $data['message'] = '酒店修改成功';
                    }else{
                        $data['status'] = 0;
                        $data['message'] = $this->showError($data_model->getErrors());
                    }
                }else{
                    $data['status'] = 0;
                    $data['message'] = $this->showError($info->getErrors());
                }
            }else{
                $data['status'] = 0;
                $data['message'] = '你无权作此操作';
            }
            echo json_encode($data);
            Yii::app()->end();
        }
        if(!$info){
            $message = '不存在此数据';
            $this->renderPartial('404',array('message'=>$message));
            Yii::app()->end();
        }
        if($info->is_link==0){
            $message = '修改链接已关闭';
            $this->renderPartial('404',array('message'=>$message));
            Yii::app()->end();
        }

        $city_array = CityArea::model()->findAll('city_id=:city_id and status=:status',array(':city_id'=>$info->city_id,':status'=>1));
        if($city_array){
            $people = Xtutuquan::renqunArr();
            $theme = Xtutuquan::zhutiArr();
            $city_info  = CreateCity::model()->findByPk($info->city_id);
            $this->layout = '/layouts/dialog';
            if($info){
                //获取附表
                $info_data = ArticleData::model()->find('article_id=:article_id',array(':article_id'=>$info->id));
                //获取酒店图集
                $image_info = ArticleImages::model()->findAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'public',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                //获取住宿图集
                $image_zhusu_info = ArticleImages::model()->findAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'zhusu',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                //获取美食图集
                $image_food_info = ArticleImages::model()->findAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'food',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                //获取好玩的图集
                $image_happy_info = ArticleImages::model()->findAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'happy',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                //获取周边
                $ambitus_info = ArticleAmbitus::model()->with('au')->findAll('source_id=:source_id and status=:status',array(':source_id'=>$info->id,':status'=>1));

                $this->render('hotelUpdate',array('image_happy_info'=>$image_happy_info,'image_food_info'=>$image_food_info,'image_zhusu_info'=>$image_zhusu_info,'ambitus_info'=>$ambitus_info,'image_info'=>$image_info,'info_data'=>$info_data,'info'=>$info,'city'=>$city_array,'people'=>$people,'theme'=>$theme,'city_info'=>$city_info));
            }else{
                exit('你无此权限');
            }
        }else{
            exit('总后台添加区域数据');
        }
    }

    public function actionFarmUpdate(){
        Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
        $token = CHtml::encode(Yii::app()->request->getParam('token'));
        $info = Article::model()->find('token=:token',array(':token'=>$token));
        if(Yii::app()->request->isPostRequest){
            if(!$_POST['thumb']){
                $data['status'] = 0;
                $data['message'] = '请上传缩略图';
                echo json_encode($data);
                Yii::app()->end();
            }else{
                $_POST['Article']['thumb'] = $_POST['thumb'];
            }
            $_POST['Article']['people'] = implode(",",$_POST['people']);
            $_POST['Article']['theme'] = implode(",",$_POST['theme']);
            if($info){
                $info->setAttributes($_POST['Article']);
                if($info->update()){
                    $id = $info->id;
                    $data_model = ArticleData::model()->find('article_id=:article_id',array(':article_id'=>$id));
                    //写入附表Data
                    $data_model->content = CHtml::encode($_POST['content']);
                    $data_model->setAttributes($_POST['ArticleData']);
                    if($data_model->update()){
                        //图片  设为删除   is_delete = 0
                        ArticleImages::model()->deleteAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'public',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                        //添加新图片地址
                        if($_POST['image_path']){
                            $image_arr = $_POST['image_path'];
                            foreach($image_arr as $k=>$v){
                                Xtutuquan::createArticleImage($id,'public',$v);
                            }
                        }
                        //图片 住宿 设为删除
                        ArticleImages::model()->deleteAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'zhusu',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                        //添加新图片地址
                        if($_POST['image_zhusu_path']){
                            $image_arr = $_POST['image_zhusu_path'];
                            foreach($image_arr as $k=>$v){
                                Xtutuquan::createArticleImage($id,'zhusu',$v);
                            }
                        }
                        //图片 美食 设为删除
                        ArticleImages::model()->deleteAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'food',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                        //添加新图片地址
                        if($_POST['image_food_path']){
                            $image_arr = $_POST['image_food_path'];
                            foreach($image_arr as $k=>$v){
                                Xtutuquan::createArticleImage($id,'food',$v);
                            }
                        }
                        //图片 好玩的 设为删除
                        ArticleImages::model()->deleteAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'happy',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                        //添加新图片地址
                        if($_POST['image_happy_path']){
                            $image_arr = $_POST['image_happy_path'];
                            foreach($image_arr as $k=>$v){
                                Xtutuquan::createArticleImage($id,'happy',$v);
                            }
                        }
                        //修改  周边表status = 0;
                        ArticleAmbitus::model()->deleteAll('source_id=:source_id and status=:status',array(':source_id'=>$info->id,':status'=>1));
                        //新增周边
                        if($_POST['relation']){
                            $relation_arr = $_POST['relation'];
                            foreach($relation_arr as $k=>$v){
                                Xtutuquan::createArticleAmbitus($id,$v);
                            }
                        }
                        //写入周边
                        $data['status'] = 1;
                        $data['message'] = '农家院修改成功';
                    }else{
                        $data['status'] = 0;
                        $data['message'] = $this->showError($data_model->getErrors());
                    }
                }else{
                    $data['status'] = 0;
                    $data['message'] = $this->showError($info->getErrors());
                }
            }else{
                $data['status'] = 0;
                $data['message'] = '你无权作此操作';
            }
            echo json_encode($data);
            Yii::app()->end();
        }
        if(!$info){
            $message = '不存在此数据';
            $this->renderPartial('404',array('message'=>$message));
            Yii::app()->end();
        }
        if($info->is_link==0){
            $message = '修改链接已关闭';
            $this->renderPartial('404',array('message'=>$message));
            Yii::app()->end();
        }

        $city_array = CityArea::model()->findAll('city_id=:city_id and status=:status',array(':city_id'=>$info->city_id,':status'=>1));
        if($city_array){
            $people = Xtutuquan::renqunArr();
            $theme = Xtutuquan::zhutiArr();
            $city_info  = CreateCity::model()->findByPk($info->city_id);
            $this->layout = '/layouts/dialog';
            if($info){
                //获取附表
                $info_data = ArticleData::model()->find('article_id=:article_id',array(':article_id'=>$info->id));
                //获取农家院图集
                $image_info = ArticleImages::model()->findAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'public',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                //获取住宿图集
                $image_zhusu_info = ArticleImages::model()->findAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'zhusu',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                //获取美食图集
                $image_food_info = ArticleImages::model()->findAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'food',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                //获取好玩的图集
                $image_happy_info = ArticleImages::model()->findAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'happy',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                //获取周边
                $ambitus_info = ArticleAmbitus::model()->with('au')->findAll('source_id=:source_id and status=:status',array(':source_id'=>$info->id,':status'=>1));

                $this->render('farmUpdate',array('image_happy_info'=>$image_happy_info,'image_food_info'=>$image_food_info,'image_zhusu_info'=>$image_zhusu_info,'ambitus_info'=>$ambitus_info,'image_info'=>$image_info,'info_data'=>$info_data,'info'=>$info,'city'=>$city_array,'people'=>$people,'theme'=>$theme,'city_info'=>$city_info));
            }else{
                exit('你无此权限');
            }
        }else{
            exit('总后台添加区域数据');
        }
    }
    public function actionResortUpdate(){
        Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
        $token = CHtml::encode(Yii::app()->request->getParam('token'));
        $info = Article::model()->find('token=:token',array(':token'=>$token));
        if(Yii::app()->request->isPostRequest){
            if(!$_POST['thumb']){
                $data['status'] = 0;
                $data['message'] = '请上传缩略图';
                echo json_encode($data);
                Yii::app()->end();
            }else{
                $_POST['Article']['thumb'] = $_POST['thumb'];
            }
            $_POST['Article']['people'] = implode(",",$_POST['people']);
            $_POST['Article']['theme'] = implode(",",$_POST['theme']);
            if($info){
                $info->setAttributes($_POST['Article']);
                if($info->update()){
                    $id = $info->id;
                    $data_model = ArticleData::model()->find('article_id=:article_id',array(':article_id'=>$id));
                    //写入附表Data
                    $data_model->content = CHtml::encode($_POST['content']);
                    $data_model->setAttributes($_POST['ArticleData']);
                    if($data_model->update()){
                        //图片  设为删除   is_delete = 0
                        ArticleImages::model()->deleteAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'public',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                        //添加新图片地址
                        if($_POST['image_path']){
                            $image_arr = $_POST['image_path'];
                            foreach($image_arr as $k=>$v){
                                Xtutuquan::createArticleImage($id,'public',$v);
                            }
                        }
                        //图片 住宿 设为删除
                        ArticleImages::model()->deleteAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'zhusu',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                        //添加新图片地址
                        if($_POST['image_zhusu_path']){
                            $image_arr = $_POST['image_zhusu_path'];
                            foreach($image_arr as $k=>$v){
                                Xtutuquan::createArticleImage($id,'zhusu',$v);
                            }
                        }
                        //图片 美食 设为删除
                        ArticleImages::model()->deleteAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'food',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                        //添加新图片地址
                        if($_POST['image_food_path']){
                            $image_arr = $_POST['image_food_path'];
                            foreach($image_arr as $k=>$v){
                                Xtutuquan::createArticleImage($id,'food',$v);
                            }
                        }
                        //图片 好玩的 设为删除
                        ArticleImages::model()->deleteAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'happy',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                        //添加新图片地址
                        if($_POST['image_happy_path']){
                            $image_arr = $_POST['image_happy_path'];
                            foreach($image_arr as $k=>$v){
                                Xtutuquan::createArticleImage($id,'happy',$v);
                            }
                        }
                        //修改  周边表status = 0;
                        ArticleAmbitus::model()->deleteAll('source_id=:source_id and status=:status',array(':source_id'=>$info->id,':status'=>1));
                        //新增周边
                        if($_POST['relation']){
                            $relation_arr = $_POST['relation'];
                            foreach($relation_arr as $k=>$v){
                                Xtutuquan::createArticleAmbitus($id,$v);
                            }
                        }
                        //写入周边
                        $data['status'] = 1;
                        $data['message'] = '度假村修改成功';
                    }else{
                        $data['status'] = 0;
                        $data['message'] = $this->showError($data_model->getErrors());
                    }
                }else{
                    $data['status'] = 0;
                    $data['message'] = $this->showError($info->getErrors());
                }
            }else{
                $data['status'] = 0;
                $data['message'] = '你无权作此操作';
            }
            echo json_encode($data);
            Yii::app()->end();
        }
        if(!$info){
            $message = '不存在此数据';
            $this->renderPartial('404',array('message'=>$message));
            Yii::app()->end();
        }
        if($info->is_link==0){
            $message = '修改链接已关闭';
            $this->renderPartial('404',array('message'=>$message));
            Yii::app()->end();
        }

        $city_array = CityArea::model()->findAll('city_id=:city_id and status=:status',array(':city_id'=>$info->city_id,':status'=>1));
        if($city_array){
            $people = Xtutuquan::renqunArr();
            $theme = Xtutuquan::zhutiArr();
            $city_info  = CreateCity::model()->findByPk($info->city_id);
            $this->layout = '/layouts/dialog';
            if($info){
                //获取附表
                $info_data = ArticleData::model()->find('article_id=:article_id',array(':article_id'=>$info->id));
                //获取酒店图集
                $image_info = ArticleImages::model()->findAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'public',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                //获取住宿图集
                $image_zhusu_info = ArticleImages::model()->findAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'zhusu',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                //获取美食图集
                $image_food_info = ArticleImages::model()->findAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'food',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                //获取好玩的图集
                $image_happy_info = ArticleImages::model()->findAll('type=:type and article_id=:article_id and is_show=:is_show and is_delete=:is_delete',array(':type'=>'happy',':article_id'=>$info->id,':is_show'=>1,':is_delete'=>0));
                //获取周边
                $ambitus_info = ArticleAmbitus::model()->with('au')->findAll('source_id=:source_id and status=:status',array(':source_id'=>$info->id,':status'=>1));

                $this->render('resortUpdate',array('image_happy_info'=>$image_happy_info,'image_food_info'=>$image_food_info,'image_zhusu_info'=>$image_zhusu_info,'ambitus_info'=>$ambitus_info,'image_info'=>$image_info,'info_data'=>$info_data,'info'=>$info,'city'=>$city_array,'people'=>$people,'theme'=>$theme,'city_info'=>$city_info));
            }else{
                exit('你无此权限');
            }
        }else{
            exit('总后台添加区域数据');
        }
    }
    public function actionPickUpdate(){
        Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
        $token = CHtml::encode(Yii::app()->request->getParam('token'));
        $info = Article::model()->find('token=:token',array(':token'=>$token));
        if(Yii::app()->request->isPostRequest){
            if(!$_POST['thumb']){
                $data['status'] = 0;
                $data['message'] = '请上传缩略图';
                echo json_encode($data);
                Yii::app()->end();
            }else{
                $_POST['Article']['thumb'] = $_POST['thumb'];
            }
            $_POST['Article']['pick'] = implode(",",$_POST['caizhai']);
            if($info){
                $info->setAttributes($_POST['Article']);
                if($info->update()){
                    $id = $info->id;
                    $data_model = ArticleData::model()->find('article_id=:article_id',array(':article_id'=>$id));
                    //写入附表Data
                    $data_model->content = CHtml::encode($_POST['content']);
                    $data_model->setAttributes($_POST['ArticleData']);
                    if($data_model->update()){
                        //修改  周边表status = 0;
                        ArticleAmbitus::model()->deleteAll('source_id=:source_id and status=:status',array(':source_id'=>$info->id,':status'=>1));
                        //新增周边
                        if($_POST['relation']){
                            $relation_arr = $_POST['relation'];
                            foreach($relation_arr as $k=>$v){
                                Xtutuquan::createArticleAmbitus($id,$v);
                            }
                        }
                        //写入周边
                        $data['status'] = 1;
                        $data['message'] = '采摘园修改成功';
                    }else{
                        $data['status'] = 0;
                        $data['message'] = $this->showError($data_model->getErrors());
                    }
                }else{
                    $data['status'] = 0;
                    $data['message'] = $this->showError($info->getErrors());
                }
            }else{
                $data['status'] = 0;
                $data['message'] = '你无权作此操作';
            }
            echo json_encode($data);
            Yii::app()->end();
        }
        if(!$info){
            $message = '不存在此数据';
            $this->renderPartial('404',array('message'=>$message));
            Yii::app()->end();
        }
        if($info->is_link==0){
            $message = '修改链接已关闭';
            $this->renderPartial('404',array('message'=>$message));
            Yii::app()->end();
        }

        $city_array = CityArea::model()->findAll('city_id=:city_id and status=:status',array(':city_id'=>$info->city_id,':status'=>1));
        if($city_array){
            $pick_arr = Xtutuquan::caizhaiArr();
            $city_info  = CreateCity::model()->findByPk($info->city_id);
            $this->layout = '/layouts/dialog';
            if($info){
                //获取附表
                $info_data = ArticleData::model()->find('article_id=:article_id',array(':article_id'=>$info->id));
                //获取周边
                $ambitus_info = ArticleAmbitus::model()->with('au')->findAll('source_id=:source_id and status=:status',array(':source_id'=>$info->id,':status'=>1));

                $this->render('pickUpdate',array('pick'=>$pick_arr,'ambitus_info'=>$ambitus_info,'info_data'=>$info_data,'info'=>$info,'city'=>$city_array,'city_info'=>$city_info));
            }else{
                exit('你无此权限');
            }
        }else{
            exit('总后台添加区域数据');
        }
    }




    public function actionGetMap()
    {
        Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
        $this->layout = '/layouts/dialog';
        $this->render('/public/get_map');
    }
}